package cn.txun.csmall.gateway.filters;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 网关过滤器必须实现一个接口GlobalFilter
 * 如果想定义多个过滤器执行顺序
 * 还有实现接口Ordered
 */

@Component
public class MyFilter02 implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
       //chain.filter()调用之前编写的逻辑代码，都属pre时间
        System.out.println("filter02执行了pre");
        //过滤器方向，执行后续的内容
        Mono<Void> result = chain.filter(exchange);//生成一个继续执行的过滤器后的Mono
        //chain.filter()调用之后编写的逻辑代码，都属post时间
        System.out.println("filter02执行了post");
        return result;
    }

    @Override
    public int getOrder() {
        return  5;
    }
}
